<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
<title></title>
</head>
<script>
    var txt="<musiclist><music>";
    txt=txt+"<songname>星晴</songname>";
    txt=txt+"<ci>周杰伦</ci>";
    txt=txt+"<qu>周杰伦</qu>";
    txt=txt+"<singer>周杰伦</singer>";
    txt=txt+"</music><music>";
    txt=txt+"<songname>唯一</songname>";
    txt=txt+"<ci>王力宏</ci>";
    txt=txt+"<qu>王力宏</qu>";
    txt=txt+"<singer>王力宏</singer>";
    txt=txt+"</music></musiclist>";
function get_xml(){
	var xmldoc,displayText="";
    if (window.DOMParser){
        parser=new DOMParser();
        xmldoc=parser.parseFromString(txt,"text/xml");
    }else{ // Internet Explorer
        xmldoc=new ActiveXObject("Microsoft.XMLDOM");
        xmldoc.async=false;
        xmldoc.loadXML(txt);
    }
    var musics = xmldoc.getElementsByTagName("music");
    for(var i=0;i<musics.length;i++) {
        var music = musics[i];
        var songname = music.getElementsByTagName("songname")[0].firstChild.data;
        var ci = music.getElementsByTagName("ci")[0].firstChild.data;
        var qu = music.getElementsByTagName("qu")[0].firstChild.data;
        var singer = music.getElementsByTagName("singer")[0].firstChild.data;
        displayText+="歌曲名称："+songname+'&emsp;作词：'+ci+'&emsp;作曲：'+qu+'&emsp;歌曲原唱：'+singer+'<br>';
    }
	div.innerHTML=displayText;
}
</script>
<body>
<input type="button" value="获取歌曲信息" onClick="get_xml()">
<br>
<br>
<div id="div"></div>
</body>
</html>
